<?php

namespace app\common\logic;

use think\Model;

class FullUser extends Model
{
    protected $table = 'sys_v_user_depart';

    protected function getStatusAttr($value)
    {
        if ($value == 1)
            return '已关注';
        elseif ($value == 2)
            return '已禁用';
        elseif ($value == 4)
            return '未关注';
        else
            return '未知';
    }

    /**
     * 根据用户Id返回用户基本信息
     * @param $user_id
     * @return array|false|\PDOStatement|string|Model
     * @author wb <pithyone@vip.qq.com>
     */
    public static function getUserById($user_id)
    {
        $ret = self::where(['user_id' => $user_id])->field('user_id,name,depart_name,avatar')->find();
        return $ret;
    }

    /**
     * 根据部门筛选成员
     * @param $dptId
     * @return string|array
     * @author wb <pithyone@vip.qq.com>
     */
    public static function getListByDptId($dptId)
    {
        $ids = Department::getChildIds($dptId);
        $rows = empty(input('rows')) ? config('paginate.list_rows') : input('rows');
        $list = self::where(['depart_id' => ['in', $ids]])->order('depart_code,user_id')->paginate($rows);
        $ret = $list->render();
        return $ret;
    }

    /**
     * 根据部门筛选成员
     * @param $dptId
     * @return string
     * @author wb <pithyone@vip.qq.com>
     */
    public static function getListByDptIdLike($dptId, $keyword)
    {
        $ids = Department::getChildIds($dptId);
        $rows = empty(input('rows')) ? config('paginate.list_rows') : input('rows');
        $list = self::where(['name|moblie' => ['like', '%' . $keyword . '%'], 'depart_id' => ['in', $ids]])
            ->order('user_id')->paginate($rows);
        $ret = $list->render();
        return $ret;
    }

    public static function getList($where)
    {
        $rows = empty(input('rows')) ? config('paginate.list_rows') : input('rows');
        $list = self::where($where)->order('user_id')->paginate($rows);
        $ret = $list->render();
        return $ret;
    }
}